home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / libcruft / misc / f77-fcn.h < prev    next >
C/C++ Source or Header  |  1997-02-08  |  3KB  |  128 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. /* Modified by Klaus Gebhardt, 1997 */
  24.  
  25. #if !defined (octave_f77_fcn_h)
  26. #define octave_f77_fcn_h 1
  27.  
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31.  
  32. #include <setjmp.h>
  33.  
  34. /* Some Fortran compilers append underscores or generate uppercase
  35.    external names. */
  36.  
  37. #if defined (F77_APPEND_UNDERSCORE)
  38. #if defined (F77_UPPERCASE_NAMES)
  39. #define F77_FCN(f, F) F##_
  40. #else
  41. #define F77_FCN(f, F) f##_
  42. #endif
  43. #else
  44. #if defined (F77_UPPERCASE_NAMES)
  45. #define F77_FCN(f, F) F
  46. #else
  47. #define F77_FCN(f, F) f
  48. #endif
  49. #endif
  50.  
  51. /* How to print an error for the F77_XFCN macro. */
  52.  
  53. #if defined (F77_UPPERCASE_NAMES)
  54. #define F77_XFCN_ERROR(f, F) \
  55.   (*current_liboctave_error_handler) \
  56.     ("exception encountered in Fortran subroutine %s", #F)
  57. #else
  58. #define F77_XFCN_ERROR(f, F) \
  59.   (*current_liboctave_error_handler) \
  60.     ("exception encountered in Fortran subroutine %s", #f)
  61. #endif
  62.  
  63. /* This can be used to call a Fortran subroutine that might call
  64.    XSTOPX.  XSTOPX will call lonjmp with f77_context and we'll return,
  65.    call the error function, restore the previous context.  After using
  66.    this macro, error_state should be checked. */
  67.  
  68. #define F77_XFCN(f, F, args) \
  69.   do \
  70.     { \
  71.       jmp_buf saved_f77_context; \
  72.       f77_exception_encountered = 0; \
  73.       copy_f77_context ((char *) f77_context, (char *) saved_f77_context, \
  74.             sizeof (jmp_buf)); \
  75.       if (setjmp (f77_context)) \
  76.     { \
  77.       f77_exception_encountered = 1; \
  78.       F77_XFCN_ERROR (f, F); \
  79.     } \
  80.       else \
  81.     F77_FCN (f, F) args; \
  82.       copy_f77_context ((char *) saved_f77_context, (char *) f77_context, \
  83.             sizeof (jmp_buf)); \
  84.     } \
  85.   while (0)
  86.  
  87. #define F77_YXFCN(f, F, rc, args) \
  88.   do \
  89.     { \
  90.       jmp_buf saved_f77_context; \
  91.       f77_exception_encountered = 0; \
  92.       copy_f77_context ((char *) f77_context, (char *) saved_f77_context, \
  93.             sizeof (jmp_buf)); \
  94.       if (setjmp (f77_context)) \
  95.     { \
  96.       f77_exception_encountered = 1; \
  97.       F77_XFCN_ERROR (f, F); \
  98.     } \
  99.       else \
  100.     rc = F77_FCN (f, F) args; \
  101.       copy_f77_context ((char *) saved_f77_context, (char *) f77_context, \
  102.             sizeof (jmp_buf)); \
  103.     } \
  104.   while (0)
  105.  
  106. /* So we can check to see if an exception has occurred. */
  107. extern int f77_exception_encountered;
  108.  
  109. /* For setjmp/longjmp. */
  110. extern jmp_buf f77_context;
  111.  
  112. /* Defining this as a separate function allows us to avoid having to
  113.    include string.h in this file. */
  114.  
  115. extern void copy_f77_context (void *, void *, unsigned int);
  116.  
  117. #ifdef __cplusplus
  118. }
  119. #endif
  120.  
  121. #endif
  122.  
  123. /*
  124. ;;; Local Variables: ***
  125. ;;; mode: C++ ***
  126. ;;; End: ***
  127. */
  128.